﻿using Microsoft.Xna.Framework.Audio;
namespace game.character.bullet
{

    public class EnemyBullet : Bullet
    {
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="origin">Origin</param>
        /// <param name="target">Target</param>
        public EnemyBullet(Microsoft.Xna.Framework.Graphics.Texture2D texture,
                Microsoft.Xna.Framework.Vector2 origin, Microsoft.Xna.Framework.Vector2 target,
                Microsoft.Xna.Framework.Vector2 additionalVelocity)
            : base(texture, origin, target, additionalVelocity)
        {
            BulletBody.CollisionCategories = Global.PhysicsCategory.EnemyBullet;
            BulletBody.CollidesWith = Global.PhysicsCategory.AllBut(Global.PhysicsCategory.Enemy | Global.PhysicsCategory.EnemyBullet | Global.PhysicsCategory.ActorBullet);
            Damage = 1000;
        }

        /// <summary>
        /// On Collision Method
        /// </summary>
        public override bool OnCollision(FarseerPhysics.Dynamics.Fixture fixtureA, FarseerPhysics.Dynamics.Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            // Collides with level.
            if ((fixtureB.CollisionCategories & Global.PhysicsCategory.Level) != 0)
            {
                Destroyed = true;
                return false;
            }
            // Collides with level.
            if ((fixtureB.CollisionCategories & (Global.PhysicsCategory.Actor)) != 0)
            {
                GameCharacter Character = fixtureB.Body.UserData as GameCharacter;
                Character.Battler.DecreaseHP(Damage);
                Character.OnHit();
                Global.Camera.Shake(8.0f, 200.0f, 1);
                Destroyed = true;
                return false;
            }
            return ((fixtureA.CollidesWith & fixtureB.CollisionCategories) != 0);
        }

    }

}